/**
 * 
 */
package com.tompai.datagather.mail;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.tompai.datagather.common.MybatisUtil;
import com.tompai.datagather.dao.TwitterAcountsMapper;

/**
 * @author SIKE_03
 *
 */
public class SendMailSchedule {

	//static int aNum=0;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		TwitterAcountsMapper acountsMapper= MybatisUtil.getSession().getMapper(TwitterAcountsMapper.class);
		int aNum=acountsMapper.selectAccountNumber();
		//发送邮件查询统计结果//
		Runnable runnable = new Runnable() {  
            public void run() {
            	//System.out.println("Hello!!");
                String timeFormat="yyyy-MM-dd HH:mm:ss";//"E yyyy.MM.dd 'at' hh:mm:ss a zzz"
        		Date dNow = new Date();
        		SimpleDateFormat ft = new SimpleDateFormat(timeFormat);
        		//System.out.println("Current Date:" + ft.format(dNow));
        		int bNum = acountsMapper.selectAccountNumber();
        		System.out.println(ft.format(dNow));
        		String subject = "测试邮件:"+ft.format(dNow);
        		String content = "mail: account numbers="+bNum+"\t"+Math.subtractExact(bNum, aNum);
        		//aNum=bNum;
        		String to = "test@126.com";
        		//MailUtil.sendMail(to, subject, content);
        		System.out.println("Finished:"+content);
            }  
        };  
        
        ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();  
        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间  //
        service.scheduleAtFixedRate(runnable, 0, 1, TimeUnit.HOURS); // 
        //service.scheduleWithFixedDelay(runnable, 10, 1, TimeUnit.SECONDS);  
	}
}
